package com.dvd.djk.gdjk001;
import java.util.*;

import org.hibernate.Query;
import org.hibernate.Transaction;

import com.dvd.dao.dvd.*;

public class GDJK001Model {
	public List<TDvd> searchDvdList(int pageId ,int pageCount)
	{
		assert(pageId>0);
		List<TDvd> dvds=null;
		TDvdDAO dao=new TDvdDAO();		
		Transaction trans =dao.getSession().beginTransaction();
		dvds = dao.searchDvdList(pageId,pageCount);
		assert(pageId==0 || !dvds.isEmpty());
		trans.commit();
		dao.getSession().close();
		return dvds;
	}

	
	public long getPageCount(int perPageCount)
	{
		long count = -1;
		TDvdDAO dao=new TDvdDAO();		
		Transaction trans =dao.getSession().beginTransaction();
		count = ((Long)dao.getSession().createQuery("select count(*) from TDvd").list().get(0)-1) / perPageCount + 1;
		trans.commit();
		dao.getSession().close();
		return count;
	}

	
	public static void main(String [] args)
	{
		System.out.println(new GDJK001Model().getPageCount(15));
	}
	
	
}
